#include <dbg.h>

#include <cassert>
#include <numeric>
#include <vector>

using namespace std;

class Solution {
public:
    int pivotIndex(vector<int>& nums) {
        int sumLeft = 0, sumRight = accumulate(nums.begin(), nums.end(), 0);
        for (int i = 0; i < nums.size(); ++i) {
            sumRight -= nums[i];
            if (sumLeft == sumRight) {
                return i;
            }
            sumLeft += nums[i];
        }

        return -1;
    }
};

int main() {
    Solution s;

    vector<int> nums1{1, 7, 3, 6, 5, 6};
    vector<int> nums2{1, 2, 3};
    vector<int> nums3{2, 1, -1};

    assert(s.pivotIndex(nums1) == 1);
    assert(s.pivotIndex(nums2) == 0);
    assert(s.pivotIndex(nums3) == 0);

    return 0;
}